# -*- coding: utf-8 -*-
class permission(object):
    #--------------------------权限---------------------
    # 站点基本信息(1-20)
    perm_baseinfo = 1 # 维护站点基本信息 
    perm_perm = 2 # 管理权限
    perm_op = 3 # 管理操作
    perm_role = 4 # 管理角色
    perm_user = 5 # 管理用户
    
    #--------------------------操作---------------------
    op_view = 1 # 查看
    op_add = 2 # 添加
    op_change = 3 # 修改
    op_del = 4 # 删除
    op_manage = 5 # 管理全部(主要针对需要按具体个数来分配权限的情况)
    op_check = 6 # 审核
    op_ban_user = 7 # 禁止用户
    op_online = 8 # 上线
    
    #--------------------------权限存储容器---------------
    __perm_ids = []
    __int_ref = 1; __tuple_ref = (1,0)
    #--------------------------方法----------------------
    def assign_perm_ids(self,perm_ids):
        if perm_ids != None:
            self.__perm_ids = perm_ids
        else:
            self.__perm_ids = []
            
    def get_perm_ids(self):
        return self.__perm_ids
        
    def check_perm_op(self,perm_id,op_id):
        return ((perm_id,op_id) in self.__perm_ids)

    def check_perm(self,perm_id):
        return ((perm_id,self.op_view) in self.__perm_ids)

    def check_perm_op_list(self,perm_ids):
        chk = False
        for (pid,oid) in perm_ids:
            if (pid,oid) in self.__perm_ids:
                chk = True
                break
        return chk
    def check_perm_list(self,perm_ids):
        chk = False
        for obj in perm_ids:
            if type(obj) == type(self.__int_ref):
                if (obj,self.op_view) in self.__perm_ids:
                    chk = True
                    break
            elif type(obj) == type(self.__tuple_ref):
                if obj in self.__perm_ids:
                    chk = True
                    break
            else: pass
        return chk

